package edu.stanford.hardon.Media;

import java.util.Date;

import android.os.Bundle;

public abstract class Media {
	
	private Long dbID;
	private Long tripID;
	protected MediaType type;
	
	// Location attributes
	private Double lat;
	private Double lng;
	private Double alt;
	
	// Timestamps
	private Date timeCaptured;
	private Date timeUploaded;
	
	// Association with other media (as an annotation)
	private Long parentID;
	
	public Media() {}
	
	public Media(Long dbID, Long tripID, MediaType type, Double lat, Double lng, Double alt, Date timeCaptured, Date timeUploaded, Long parentID) {
		this.dbID = dbID;
		this.tripID = tripID;
		this.type = type;
		this.lat = lat;
		this.lng = lng;
		this.alt = alt;
		this.timeCaptured = timeCaptured;
		this.timeUploaded = timeUploaded;
		this.parentID = parentID;
	}
	
	public Long getDBID(){
		return dbID;
	}
	
	public void setDBID(Long dbID){
		this.dbID = dbID;
	}
	
	public Long getTripID(){
		return tripID;
	}
	
	public void setTripID(Long tripID){
		this.tripID = tripID;
	}
	
	public MediaType getType(){
		return type;
	}
	
	public void setType(MediaType newType){
		type = newType;
	}
	
	public Double getLat() {
		return lat;
	}
	
	public void setLat(Double lat) {
		this.lat = lat;
	}
	
	public Double getLng() {
		return lng;
	}
	
	public void setLng(Double lng) {
		this.lng = lng;
	}
	
	public Double getAlt() {
		return alt;
	}
	
	public void setAlt(Double alt) {
		this.alt = alt;
	}
	
	public Date getTimeCaptured() {
		return timeCaptured;
	}
	
	public void setTimeCaptured(Date timeCaptured) {
		this.timeCaptured = timeCaptured;
	}
	
	public Date getTimeUploaded() {
		return timeUploaded;
	}
	
	public void setTimeUploaded(Date timeUploaded) {
		this.timeUploaded = timeUploaded;
	}
	
	public Long getParentId() {
		return parentID;
	}
	
	public void setParentId(Long parentID) {
		this.parentID = parentID;
	}
	
	public String toString() {
		String s = "{ Media Type: " + type.toString();
		s += ", DBID: " + dbID.toString();
		s += ", Trip ID: " + tripID.toString();
		s += ", Latitude: " + lat.toString();
		s += ", Longitude: " + lng.toString();
		s += ", Altitude: " + alt.toString();
		s += ", Time created: " + timeCaptured.toString();
		s += ", Time uploaded: " + timeUploaded.toString();
		s += ", Parent ID: " + parentID.toString();
		
		if (this instanceof RichMedia) {
			s += ", File path: " + ((RichMedia)this).getPath() + " }";
		} else if (this instanceof TextMedia) {
			s += ", Content: " + ((TextMedia)this).getContent() + " }";
		}
		
		return s;
	}
	
	public Bundle serialize() {
		Bundle b = new Bundle();
		b.putDouble("lat", this.lat);
		b.putDouble("lng", this.lng);
		b.putLong("timeCaptured", this.timeCaptured.getTime());
		b.putLong("timeUploaded", this.timeUploaded.getTime());
		return b;
	}
	 
}